package jmine.tec.services.io;

import java.util.LinkedList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

/**
 * Bean que representa uma aba da planilha
 * 
 * @author Kendji
 */
@XStreamAlias("services")
public class ServicesPageBean {

    @XStreamAsAttribute
    private String name;

    @XStreamImplicit
    private List<ServiceBean> services;

    /**
     * @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the services
     */
    public List<ServiceBean> getServices() {
        if (this.services == null) {
            this.services = new LinkedList<ServiceBean>();
        }
        return this.services;
    }

    /**
     * @param services the services to set
     */
    public void setServices(List<ServiceBean> services) {
        this.services = services;
    }

    /**
     * Adiciona um ServiceBean a lista de abas.
     * 
     * @param serviceBean serviceBean que será adicionado a lista de abas
     */
    public void addService(ServiceBean serviceBean) {
        this.getServices().add(serviceBean);
    }

    /**
     * Adiciona uma lista de service beans à lista
     * 
     * @param moreServices services
     */
    public void addServices(List<ServiceBean> moreServices) {
        this.getServices().addAll(moreServices);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
        result = prime * result + ((this.services == null) ? 0 : this.services.hashCode());
        return result;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        ServicesPageBean other = (ServicesPageBean) obj;
        if (this.name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!this.name.equals(other.name)) {
            return false;
        }
        if (this.services == null) {
            if (other.services != null) {
                return false;
            }
        } else if (!this.services.equals(other.services)) {
            return false;
        }
        return true;
    }

}
